/**
 * index页面的业务js
 */

// 全局变量
var bck01;// 部门ID
var isChoseWait = false;// 候诊病人
var isOwnchose = false;// 我的病人和本科病人
var pageSize = 20;
var curr = 1;
var xinkairenId;
var cbm01;
var valueArr = {};// 参数

var zhenduanyijuHtml;//诊断依据
var zhenduanyieguoHtml;//诊断结果
var shouyeActiveId;
var timeId;//记录单击事件延迟时间
var bce01 = $.cookie("employeeId");
var vaa01;
var vac01;
var bce03;
var loginName = $.cookie("loginName");
// 界面初始化完成后加载的脚本
$(document).ready(function() {
	skin();
//	showSetTable();
	initData();
	getAllParams();
//	handleAdmission();
	newOrder();
	yizhuOperation();
	$("#login_name").text($.cookie('loginName') + "欢迎您！");
	//initTopMenu(359, 360);
	// moreOperation()
	// var pageIndex=1;
	//医嘱附加信息的默认展开或者隐藏
	var temp = valueArr["p_100_105002_394"];
	if(temp == "1"){
		$("#patient_operation").removeClass("expand");
	}else if(temp == "2"){
		$("#patient_operation").addClass("expand");
	}
	yizhuOtherInfo();
	patientMoreType();
	jianyanSelectEvent();// 检验经典模式select 数据填充
	addJyFenzuguize();// 检验报告分组规则添加
	addJianchaFenzu();//检查报告分组规则添加
	showJiuzhenfanwei();//接诊范围参数控制
//	loadSelectAllList();//加载诊断信息下拉列表数据
//	tableSetClick();
	// checkboxEventtest();
	// 根据参数定时刷新候诊病人列表（暂时注释）
	// setTimeOut(houzhenPatientList(),1000*valueArr['p_100_105002_104']);
	//左侧列表收缩事件
	var contentMainState = true;
	$("#doc_directionBtn").click(function(){
		if(contentMainState){
			$('#content').animate({'left':0},200);
			$("#doc_directionBtn").animate({'left':0},200);
			contentMainState = false;
		}
		else{
			$('#content').animate({'left':250},200);
			$("#doc_directionBtn").animate({'left':250},200);
			contentMainState = true;
		}
	})
	
	/*页面上select2 控件初始化*/
//	$('#bdaSearch').select2(
//	{
//		placeholder : '全部医嘱',
//		allowClear : true,
//	});
	$("select").select2({
		language: "zh-CN"
	});
	reloadPatientInfo(vac01);//不能和yizhuOtherInfo（）换位置，计算高度需要
	
	
	
});

function initData()
{
	var parentDocument = $(window.parent.document);
	var dataobj = JSON.parse(parentDocument.find("#patientInfo").attr("data-info"));
	vaa01 = dataobj.vaa01;
	vac01 = dataobj.vac01;
	bck01 = parentDocument.find("#departmentList_jiezhen").find("option:selected").attr("id");
	$.ajax({url:rootUrl+"/clidoctor/getBce03",type:"get",dataType:"json",data:{"bce01":bce01},async:false,success:function(data){bce03 = data.map.bce03}});
}



// 获取界面参数设置
function getAllParams() {
	$.ajax({
		url : rootUrl + "/patientsearch/findSysparams",
		data : {userid:$.cookie("userId")},
		async : false,
		success : function(data) {
			var list = data.list;
			for (var i = 0; i < list.length; i++) {
				valueArr[list[i]["para_key"]] = list[i]["value"];
			}
			var jiezhenfw = valueArr.p_100_105002_100;
			if(jiezhenfw=="05" || jiezhenfw=="05")
			{
				$("#varjiezhen_fanwei").html("全院病人");
			}
		}
	});
}
// 我的病人和本科病人选中事件
function ownAdviceSelect() {
	$("#patient_own_content table tr").on("click", function() {
		$(this).addClass("choseedTr").siblings().removeClass("choseedTr");
		isOwnchose = true;
	})
}
//接诊范围根据参数设置显示
function showJiuzhenfanwei(){
	var map={
			"01":"本科室病人",
			"02":"本科室病人",
			"03":"本科室病人",
			"04":"本科室病人",
			"05":"全院病人",
			"06":"全院病人"
	}
	$("#jiezhen_fanwei").text(map[valueArr['p_100_105002_100']]);
}
// 新开返回该页面加载被新开病人的医嘱信息
// function addxkbr(){
// var xkid=$("#vac01").val();
// $("#"+xkid).trigger("click");
// }
// 医嘱单全选事件
function choseAllEvent() {
	var all = $("#advice_table table thead").find("input[type='checkbox']");
	var sub = $("#advice_table table tbody").find(".innerHead").find(
			"input[type='checkbox']");
	$(all).on("click", function() {
		if ($(all).is(':checked')) {
			$(sub).prop("checked", true);
		} else {
			$(sub).removeAttr("checked");
		}
	})
	$(sub).on("click", function() {
		var flag = true;
		$(sub).each(function(i, e) {
			if (!($(e).is(':checked'))) {
				flag = false;
			}
		})
		if (flag) {
			$(all).prop("checked", true);
		} else {
			$(all).removeAttr("checked");
		}
	})
}



// tbody tr selected
function selectTr(tbody_id) {
	$("#" + tbody_id).find("tr").on("click", function() {
		$(this).addClass("choseedTr").siblings().removeClass("choseedTr");
		xinkairenId = $(this).attr("id");
	});
}



// 根据科室刷新候诊\就诊列表
function refreshListHouzhen() {
	layer.msg('查询中....', {icon: 16,skin: 'layui-layer-msg16',shade: [0.1, '#393D49'],time:1*600}); 
	bck01 = $("#departmentList").find("option:selected").attr("id");
	houzhenPatientList();
	refreshListJiezhen();
}
// 根据科室刷新候诊\就诊列表
function refreshListJiezhen() {
	layer.msg('查询中....', {icon: 16,skin: 'layui-layer-msg16',shade: [0.1, '#393D49'],time:1*600}); 
	myJienzhenPatientList();
	benkeJiezhenPatientList();
}

// 候诊病人列表
function houzhenPatientList() {
	var jiezhenfw = valueArr.p_100_105002_100;
	$.ajax({
				url : rootUrl
						+ "/patientsearch/querywaitingandtransfertreatment",
				data : {
					lPara : jiezhenfw,
					lVAC51 : 0,
					lBCK01 : bck01,
					lBCE01 : bce01,
					BAS02 : 0001,
					currPage : 1,
					pageSize : 8
				},
				type : "get",
				dataType : 'json',
				success : function(data) {
					var houzhenpatientList = data.list;
					var html = "";
					for (var i = 0; i < houzhenpatientList.length; i++) {
						var shouzimu = makePy(houzhenpatientList[i]["vaa05"]);
						var vac01 = houzhenpatientList[i]["vac01"] + "";
						html = html + "<tr data-info='" + JSON.stringify(vac01)
								+ "'  id=" + i
								+ " onclick='reloadPatientInfo(\"" + vac01
								+ "\")' ondblclick='zhijiexinkai(\""+vac01+"\")' name='" + shouzimu + "'>";
						html = html + "<td>" + (i + 1) + "</td>";
						html = html
								+ "<td>"
								+ (typeof (houzhenpatientList[i]["vaa03"]) == 'undefined' ? ""
										: houzhenpatientList[i]["vaa03"])
								+ "</td>";
						html = html
						+ "<td>"
						+ (typeof (houzhenpatientList[i]["vaa05"]) == 'undefined' ? ""
								: houzhenpatientList[i]["vaa05"])
								+ "</td>";
						html = html
								+ "<td>"
								+ (typeof (houzhenpatientList[i]["abw02"]) == 'undefined' ? ""
										: houzhenpatientList[i]["abw02"])
								+ "</td>";
						html = html
								+ "<td>"
								+ (typeof (houzhenpatientList[i]["agep"]) == 'undefined' ? ""
										: houzhenpatientList[i]["agep"])
								+ "</td>";
						html = html
						+ "<td>"
						+ (typeof (houzhenpatientList[i]["vac10"]=='1') == '' ? "是":"否")
								+ "</td>";
						html = html
						+ "<td>"
						+ (typeof (houzhenpatientList[i]["vac06"]) == '1' ? "是":"否")
								+ "</td>";
						html = html
						+ "<td>"
						+ (typeof (houzhenpatientList[i]["bck03"]) == 'undefined' ? ""
								: houzhenpatientList[i]["bck03"])
								+ "</td>";
						html = html
						+ "<td>"
						+ (typeof (houzhenpatientList[i]["bdp02"]) == 'undefined' ? ""
								: houzhenpatientList[i]["bdp02"])
								+ "</td>";
						html = html
						+ "<td>"
						+ (typeof (houzhenpatientList[i]["bce03a"]) == 'undefined' ? ""
								: houzhenpatientList[i]["bce03a"])
								+ "</td>";
						html = html
						+ "<td>"
						+ (typeof (houzhenpatientList[i]["vac42"]) == 'undefined' ? ""
								: houzhenpatientList[i]["vac42"])
								+ "</td>";
						html = html
						+ "<td>"
						+ (typeof (houzhenpatientList[i]["vac36"]) == 'undefined' ? ""
								:new Date(houzhenpatientList[i]["vac36"]).Format("yyyy-MM-dd"))
								+ "</td>";
						html = html
						+ "<td>"
						+ (typeof (houzhenpatientList[i]["vac02"]) == 'undefined' ? ""
								: houzhenpatientList[i]["vac02"])
								+ "</td>";
						html = html + "</tr>"
					}
					$("#houzhenTableContent").empty().html(html);
					searchHouzhenren("houzhenTableContent");
					clickBtnsousuo("houzhenTableContent");
					// 候诊病人列表选择事件
					// selectTr("houzhenTableContent");
					$("#houzhenTableContent").find("tr").on(
							"click",
							function() {
								$(this).addClass("choseedTr").siblings()
										.removeClass("choseedTr");
								isChoseWait = true;
								isOwnchose = false; //本科病人设置为没选中状态
							});
				}
			});
}
/*候诊病人刷新*/
function reflushPatientWait(){
	layer.msg('刷新中....', {icon: 16,skin: 'layui-layer-msg16',shade: [0.1, '#393D49'],time:1*600}); 
//	$("#houzhenTableContent").empty();
//	houzhenPatientList();
}


/*
 * 根据人名过滤候诊病人为选中状态(两种方式：1点击查询按钮，2回车键查询)
 */
// 点击查询按钮
function clickBtnsousuo(tableId) {
	$("#sousuoHouzhenBtn").on("click", function() {
		sousuoHouzhen(tableId);
	})
}
// 查询事件
function sousuoHouzhen(tableId) {
	var str = $("#houzheSearchStr").val().toUpperCase();
	var menzhenStr = $("#houzheSearchStr").val();
	$("#" + tableId + " tr").hide();
	$("#" + tableId + " tr").each(function(i, e) {
		var temp = $(e).attr("name").toString();
		var menzhTemp = $(e).children().eq(1).text();
		if (temp.indexOf(str) >= 0||menzhTemp.indexOf(menzhenStr) >= 0) {
			$(e).show();
		}
	});

}
// 回车键查询
function searchHouzhenren(tableId) {
	$("#houzheSearchStr").keydown(function(e) {
		if (e.which === 13) {
			sousuoHouzhen(tableId);
		}
	});
}
// 我的接诊病人列表
function myJienzhenPatientList() {
	var jiezhenfw = valueArr.p_100_105002_100;
	var dl1 = $("#dl1").val();
	var dl2 = $("#dl2").val();
	var vac01=$("#vac01").val();
	$
			.ajax({
				url : rootUrl + "/patientsearch/queryvisitdoctor",
				data : {
					lVAC34 : 1,
					lDt1 : dl1,
					lDt2 : dl2,
					lPara : '01',
					VAC01 : 0,
					lBCK01 : bck01,
					lBCE01 : bce01,
					BAS02 : 0001,
					currPage : 1,
					pageSize : 500
				},
				type : "get",
				dataType : 'json',
				success : function(data) {
					var houzhenpatientList = data.list;
					var html = "";
					for (var i = 0; i < houzhenpatientList.length; i++) {
						var shouzimu = makePy(houzhenpatientList[i]["vaa05"]);
						html = html + "<tr id='"
								+ houzhenpatientList[i]["vac01"]
								+ "' onclick='reloadPatientInfo(\""
								+ houzhenpatientList[i]["vac01"]
								+ "\")' name='" + shouzimu + "'>";
						html = html + "<td>" + (i + 1) + "</td>";
						html = html
								+ "<td>"
								+ (typeof (houzhenpatientList[i]["vaa03"]) == 'undefined' ? ""
										: houzhenpatientList[i]["vaa03"])
								+ "</td>";
						html = html
						+ "<td>"
						+ (typeof (houzhenpatientList[i]["vaa05"]) == 'undefined' ? ""
								: houzhenpatientList[i]["vaa05"])
								+ "</td>";
						html = html
								+ "<td>"
								+ (typeof (houzhenpatientList[i]["abw02"]) == 'undefined' ? ""
										: houzhenpatientList[i]["abw02"])
								+ "</td>";
						html = html
								+ "<td>"
								+ (typeof (houzhenpatientList[i]["agep"]) == 'undefined' ? ""
										: houzhenpatientList[i]["agep"])
								+ "</td>";
						html = html
						+ "<td>"
						+ (typeof (houzhenpatientList[i]["vac10"]) == '1' ? "是":"否")
								+ "</td>";
						html = html
						+ "<td>"
						+ (typeof (houzhenpatientList[i]["vac06"]) == '1' ?"是":"否")
								+ "</td>";
						html = html
						+ "<td>"
						+ (typeof (houzhenpatientList[i]["bdp02"]) == 'undefined' ? ""
								: houzhenpatientList[i]["bdp02"])
								+ "</td>";
						html = html
						+ "<td>"
						+ (typeof (houzhenpatientList[i]["vac35"]) == 'undefined' ? ""
								: new Date(houzhenpatientList[i]["vac35"]).Format("yyyy-MM-dd"))
								+ "</td>";
						html = html
						+ "<td>"
						+ (typeof (houzhenpatientList[i]["bce03a"]) == 'undefined' ? ""
								: houzhenpatientList[i]["bce03a"])
								+ "</td>";
						html = html
						+ "<td>"
						+ (typeof (houzhenpatientList[i]["vac02"]) == 'undefined' ? ""
								: houzhenpatientList[i]["vac02"])
								+ "</td>";
						html = html
						+ "<td>"
						+ (typeof (houzhenpatientList[i]["vac01"]) == 'undefined' ? ""
								: houzhenpatientList[i]["vac01"])
								+ "</td>";
						html = html
						+ "<td>"
						+ (typeof (houzhenpatientList[i]["vaa01"]) == 'undefined' ? ""
								: houzhenpatientList[i]["vaa01"])
								+ "</td>";
						html = html + "</tr>"
					}
					$("#jiezhenBenrenTableContent").empty().html(html);
					
//					selectTr("jiezhenBenrenTableContent");
//					ownAdviceSelect();
					
				}
			});
}

// 本科室的接诊病人列表
function benkeJiezhenPatientList() {
	var dl1 = $("#dl1").val();
	var dl2 = $("#dl2").val();
	var jiezhenfw = valueArr.p_100_105002_100;
	$.ajax({
				url : rootUrl + "/patientsearch/queryvisitdoctor",
				data : {
					lVAC34 : 1,
					lDt1 : dl1,
					lDt2 : dl2,
					lPara : jiezhenfw,
					VAC01 : 0,
					lBCK01 : bck01,
					lBCE01 : bce01,
					BAS02 : 0001,
					currPage : 1,
					pageSize : 500
				},
				type : "get",
				dataType : 'json',
				success : function(data) {
					var houzhenpatientList = data.list;
					var html = "";
					for (var i = 0; i < houzhenpatientList.length; i++) {
						var shouzimu = makePy(houzhenpatientList[i]["vaa05"]);
						html = html + "<tr name='" + shouzimu + "'>";
						html = html + "<td>" + (i + 1) + "</td>";
						html = html
								+ "<td>"
								+ (typeof (houzhenpatientList[i]["vaa03"]) == 'undefined' ? ""
										: houzhenpatientList[i]["vaa03"])
								+ "</td>";
						html = html
						+ "<td>"
						+ (typeof (houzhenpatientList[i]["vaa05"]) == 'undefined' ? ""
								: houzhenpatientList[i]["vaa05"])
								+ "</td>";
						html = html
								+ "<td>"
								+ (typeof (houzhenpatientList[i]["abw02"]) == 'undefined' ? ""
										: houzhenpatientList[i]["abw02"])
								+ "</td>";
						html = html
								+ "<td>"
								+ (typeof (houzhenpatientList[i]["agep"]) == 'undefined' ? ""
										: houzhenpatientList[i]["agep"])
								+ "</td>";
						html = html
						+ "<td>"
						+ (typeof (houzhenpatientList[i]["vac10"]) == '1' ? "是":"否")
								+ "</td>";
						html = html
						+ "<td>"
						+ (typeof (houzhenpatientList[i]["bdp02"]) == 'undefined' ? ""
								: houzhenpatientList[i]["bdp02"])
								+ "</td>";
						html = html
						+ "<td>"
						+ (typeof (houzhenpatientList[i]["vac35"]) == 'undefined' ? ""
								: new Date(houzhenpatientList[i]["vac35"]).Format("yyyy-MM-dd"))
								+ "</td>";
						html = html
						+ "<td>"
						+ (typeof (houzhenpatientList[i]["bce03a"]) == 'undefined' ? ""
								: houzhenpatientList[i]["bce03a"])
								+ "</td>";
						html = html
						+ "<td>"
						+ (typeof (houzhenpatientList[i]["bce01a"]) == 'undefined' ? ""
								: houzhenpatientList[i]["bce01a"])
								+ "</td>";
						html = html
						+ "<td>"
						+ (typeof (houzhenpatientList[i]["vac01"]) == 'undefined' ? ""
								: houzhenpatientList[i]["vac01"])
								+ "</td>";
						html = html
						+ "<td>"
						+ (typeof (houzhenpatientList[i]["vaa01"]) == 'undefined' ? ""
								: houzhenpatientList[i]["vaa01"])
								+ "</td>";
						
						html = html + "</tr>"
					}
					$("#jiezhenBenkeTableContent").html(html);
					searchHouzhenren("jiezhenBenkeTableContent");
					clickBtnsousuo("jiezhenBenkeTableContent");
					selectTr("jiezhenBenkeTableContent");
					ownAdviceSelect();
				}
			});
}


function reloadPatientInfo(lvac01)
{
//	debugger;
//	$("#vac01").val(lvac01);
//	$("#bck01").val(bck01);
	$.ajax({
		url : rootUrl + "/patientsearch/getpatientinfo",
		data : {
			"productid" : 100,
			"programid" :103010,
			"paramno" : 29,
			"lVAC01" : lvac01
		},
		type : 'post',
		dataType : 'json',
		success : function(data) {
			if(data){
				//$("#vaa01").val(data.list[0]['vaa01']); //重要
			    laytplUrl(myurl + "/module/patient_more_info.html",data.list[0], function(data, html) {
			    	 $(".header-content-left").empty().append(html);
			    	 debugger;
			    	 var flag = $(".three-column").find(".main-header").hasClass('br_expanded');
			    	 if(flag){
			    		 $(".patientInfo_more").removeClass("hidden");
			    	 }
				});
			    
				// 检查报告
				jianchabaogao();
				// 检验报告
				jianyanbaogao(data.list[0]['vaa03']);// 简约模式
				jianyanJingdian(data.list[0]['vaa03']);// 经典模式-左边列表
				patientDoctorAdvice(lvac01, 1);// 1
				
				// 病历记录
				queryApplyFileByPatientId(data.list[0]['vaa01'],
						data.list[0]['vaa05'], lvac01);
			}
		}
	});
}

function seeMoreInfoEvent(){
	if(vaa01){
		var flag = $(".three-column").find(".main-header").hasClass('br_expanded');
		if(flag){
			$(".three-column").find(".main-header").removeClass('br_expanded');
			$(".three-column").find('.more-info-text').text('更多');
			$(".three-column").find('.caret').removeClass('caret-top');
			$('.main-content').css('top','35px');
			$(".patientInfo_more").addClass("hidden");
			$(".header-content-left ul li").removeAttr('style');
			$(".header-content-left ul li").css('margin-right','30px');
			
		}else{
			$(".three-column").find(".main-header").addClass('br_expanded');
			$(".three-column").find('.more-info-text').text('收起');
			$(".three-column").find('.caret').addClass('caret-top');
			$('.main-content').css('top','105px');
			$(".patientInfo_more").removeClass("hidden");
			$(".header-content-left ul li").css('width','160px');
			$(".header-content-left ul li").css('margin-right','0px');
		}
	}
}
function yizhuOtherInfo(){
	var flag = $("#patient_operation").hasClass("expand");
	if(flag){
		$('.yizhu_content_table').animate({'height':"92%"},"fast");
		$("#patient_operation").removeClass("expand");
		$("#patient_operation").find('.more-info-text').text('展开');
		$("#yizhujilu_content").hide();
		$("#patient_operation").find('.caret').addClass('caret-top');
	}else{
		$('.yizhu_content_table').animate({'height':"55%"},"fast");
		$("#patient_operation").find('.more-info-text').text('收缩');
		$("#patient_operation").addClass("expand");
		$("#yizhujilu_content").show();
		$("#patient_operation").find('.caret').removeClass('caret-top');
	}
	
	
	
}

// table折叠
function zhedie() {
	$(".innerHead").find("button").on(
			"click",
			function() {
				if ($(this).parents("tr").siblings().css("display") == "none") {
					$(this).parents("tr").find("lable").removeClass(
							"glyphicon glyphicon-chevron-up")
					$(this).parents("tr").find("lable").addClass(
							"glyphicon glyphicon-chevron-down");
					$(this).parents("tr").siblings().removeClass("hidden");
				} else {
					$(this).parents("tr").find("lable").removeClass(
							"glyphicon glyphicon-chevron-down");
					$(this).parents("tr").find("lable").addClass(
							"glyphicon glyphicon-chevron-up");
					$(this).parents("tr").siblings().addClass("hidden");
				}

			})
}


// 医嘱单tr选中事件
function adviceChoseTr() {
	$("#advice_table").find(".yizhu_details").on(
			"click",
			function() {
				$(this).addClass("choseedTr").siblings().removeClass("choseedTr");
				$(this).parents("tbody").siblings().find("tr").removeClass("choseedTr");
			});
}
// 病人医嘱记录
function patientDoctorAdvice(lvac01, curr) {
	var that = this;
	// that.frist = true;
	$.ajax({
		url : rootUrl + "/doctoradvice/getpatientsdoctoradvice",
		type : "post",
		async : false,
		data : {
			"lVAF06" : lvac01,
			"lVAF04" : 1,
			"lBCE01A" : bce01,
//			currPage : curr,
//			pageSize : pageSize,
			VAF74 : "",
			VAF36 : ""
		},
		dataType : 'json',
		success : function(data) {
			that.laytplUrl_T(myurl + "/module/advice_table.html", data,
					function(data, html) {
						$("#advice_table").html(html);
//						$("#adviceTable_body").css("height",($("#advice_table").innerHeight()-$("#adviceTable_head").outerHeight())+"px");
						choseAllEvent();// 全选事件
						otherProperties();
						checkboxEvent1();
						checkboxEvent4();
						checkboxEvent8();
						advicetongzu();// 同组记录
						adviceChoseTr();// 医嘱tr选中事件
//						printCheckedEvent();//打印设置
						backAdviceStyle();//医嘱作废样式
						// checkboxEvent();//checkbox选中事件
						// deleteAdivce();
						// table折叠
						zhedie();
						/*var totalPage = 1;
						var pages = parseInt(data.total) % parseInt(pageSize);
						if (pages == 0) {
							totalPage = parseInt(data.total)
									/ parseInt(pageSize);
						} else {
							totalPage = parseInt(data.total - pages)
									/ parseInt(pageSize) + 1
						}

						laypage({
							cont : 'page',
							pages : totalPage,
							skip : true, // 是否开启跳页
//							skin : '#33b818',
							groups : 5, // 连续显示分页数
							curr : curr || 1,
							jump : function(obj, first) {
								if (!first) {
									patientDoctorAdvice(lvac01, obj.curr);
								}
							}
						});*/
					});
		}
	});
}
//作废样式
function backAdviceStyle(){
	$(".yizhu_details").each(function(index, ele) {
		var fstatus=JSON.parse($(ele).attr("data-info")).fstatus;
		if(fstatus=="医嘱退费"){
			$(this).addClass("backAdvice");
		}
	})
}
// 医嘱单同组
function advicetongzu() {
	var tzTdindex = [ 3, 6 ];
	$("#advice_table tbody").each(function(index, ele) {
						var vaf59Arr = [];
						var adviceList = $(ele).find(".yizhu_details");
						for (var k = 0; k < adviceList.length; k++) {
							var dataobj = JSON.parse($(adviceList[k]).attr("data-info"));
							vaf59Arr.push(dataobj.vaf59);
						}
						vaf59Arr = vaf59Arr.unique2();
						var resultArr = [];
						for (var i = 0; i < vaf59Arr.length; i++) {
							var tongzuEditArr = [];
							for (var j = 0; j < adviceList.length; j++) {
								if (JSON.parse($(adviceList[j]).attr("data-info")).vaf59 == vaf59Arr[i]) {
									tongzuEditArr.push($(adviceList[j]).index());
								}
							}
							if (tongzuEditArr.length > 1) {

								for (var m = 0; m < tzTdindex.length; m++) {// 要同组的tr
																			// 的下标
									for (var n = 0; n < tongzuEditArr.length; n++) { // 同组的td
																						// 的下标[3,6]
										if (n == 0) { // 同组tr为第一行的，只把td的bottom
														// 去掉
											$($(ele).find("tr")[tongzuEditArr[n]]).find("td:eq("+ tzTdindex[m]+ ")").addClass("xiyaoTzCss");
										} else if (n == (tongzuEditArr.length - 1)) {// 如果为最后一行，只把text隐藏
											$($(ele).find("tr")[tongzuEditArr[n]]).find("td:eq("+ tzTdindex[m]+ ")").text("");
										} else {// 如果为中间的tr，则隐藏text,并bottom 去掉
											$($(ele).find("tr")[tongzuEditArr[n]]).find("td:eq("+ tzTdindex[m]+ ")").text("");
											$($(ele).find("tr")[tongzuEditArr[n]]).find("td:eq("+ tzTdindex[m]+ ")").addClass("xiyaoTzCss");
										}
									}
								}
							}
						}

					})
}

// 检验报告select 下拉加载
function jianyanSelectEvent() {
	var data = [ {
		"name" : "生化",
		"value" : "sh"
	}, {
		"name" : "五分类检验报告",
		"value" : "wfljybg"
	}, {
		"name" : "统计",
		"value" : "tj"
	}, {
		"name" : "检验申请单",
		"value" : "jysqd"
	}, {
		"name" : "样本条码",
		"value" : "ybtm"
	}, {
		"name" : "样本检验A4",
		"value" : "ybjyA4"
	}, {
		"name" : "性激素检验报告（实验室）",
		"value" : "xjs_sys"
	}, {
		"name" : "微量元素检验报告",
		"value" : "wlys"
	}, {
		"name" : "酶标仪",
		"value" : "mby"
	}, {
		"name" : "实验室报告单",
		"value" : "sysbgd"
	}, {
		"name" : "性激素检验报告（免疫）",
		"value" : "xjs_my"
	}, {
		"name" : "酶标测试报告",
		"value" : "mbcsbg"
	}, {
		"name" : "样本条码",
		"value" : "ybtm"
	}, {
		"name" : "质控图",
		"value" : "zkt"
	}, {
		"name" : "血液查询",
		"value" : "xycx"
	}, {
		"name" : "血液_病人登记",
		"value" : "xy_brdj"
	}, {
		"name" : "血液_血液鉴定",
		"value" : "xy_xyjd"
	}, {
		"name" : "血库血液出库单",
		"value" : "xk_ckd"
	}, {
		"name" : "血库血液入库单）",
		"value" : "xk_rkd"
	}, {
		"name" : "血库血液报废单",
		"value" : "xk_bfd"
	}, {
		"name" : "血库血液退库单",
		"value" : "xk_tkd"
	}, {
		"name" : "手工报告单",
		"value" : "sgbgd"
	}, {
		"name" : "微量元素",
		"value" : "wlys"
	} ]

	for (var i = 0; i < data.length; i++) {
		var html = "<option>";
		html += data[i].name;
		html += "</option>";
		$("#jiangyan_baogaodan").append(html);
	}
}
//检查报告select 分组加载
function addJianchaFenzu(){
	var html;
	var data = [ {"name" : "姓名","value" : "paa07"}, {"name" : "检查仪器","value" : "bhf03"}, {"name" : "影像提示","value" : "pab11"},
	             {"name" : "影像号","value" : "paa06"}, {"name" : "阳性提示","value" : ""}, {"name" : "业务范围","value" : "acf02"}, 
	             {"name" : "审核时间","value" : "pab13"}]
	html = "<option value='-1'>-请选择-</option>";
	for (var i = 0; i < data.length; i++) {
		html += "<option value=" + data[i].value + ">";
		html += data[i].name;
		html += "</option>";
	}
	$(".jiancha_fenzu").empty().append(html);
	$("#jiancha_fenzu1").val("bhf03");
	$("#jiancha_fenzu2").val("acf02");
	$("#jiancha_fenzu3").val("pab13");
}
//检查报告
function jianchabaogao() {
	var that = this;
	var url = rootUrl + "/patientcase/doctorviewimageresult";
	var params = {};
	params.ACF01 = 3;
	params.VAA01 = $("#vaa01").val();//
	params.VAA07 = $("#vac01").val();
	params.fpass = "";
	params.fport = "";
	params.VAA07 = "";
	params.currPage = 1;
	params.pageSize = 20;
	$.post(url, params, function(data) {
		var list = data.list;
		$("#jc_sj").val(JSON.stringify(list));// 存储数据
		/*if (list) {
			that.laytplUrl(myurl + "/module/Inspection_report.html",
					list, function(list, html) {
						$("#jiancha_baogao").html(html);

					});
		}*/
	});
}
//检查根据分组规则重组table
function jcRecombination() {
	if(($("#jc_sj").val())&&($("#jc_sj").val()!="[]")){
	var dataObj = JSON.parse($("#jc_sj").val());
	var fenzu1 = $("#jiancha_fenzu1").val();
	var fenzu2 = $("#jiancha_fenzu2").val();
	var fenzu3 = $("#jiancha_fenzu3").val();
	dataObj=$.extend(dataObj,{"fenzu1":fenzu1},{"fenzu2":fenzu2},{"fenzu3":fenzu3},{"type":"jc_baogao"});
	diguiEvent(dataObj)	;
	}else{
		$("#jiancha_baogao").empty().html("暂无数据");
//		layer.msg("暂无数据！" ,{time:2000,icon:0});
	}
}
//检查分组后模板绑定
function jianchaShowResult(firstArr,fenzuobj){
	var fenzu1=fenzuobj.fenzu1;
	var fenzu2=fenzuobj.fenzu2;
	var fenzu3=fenzuobj.fenzu3;
	if((fenzu1!=-1)&&(fenzu2!=-1)&&(fenzu3!=-1)){//三个分组
		
		laytplUrl(myurl + "/module/Inspection_report1.html",firstArr, function(data, html) {
			$("#jiancha_baogao").empty().html(html);
			$("#jiancha_1_table").treetable({ expandable: true,initialState : 'expanded' });
		});
	}else if((fenzu1!=-1)&&(fenzu2!=-1)){//两层分组
		
		laytplUrl(myurl + "/module/Inspection_report2.html",firstArr, function(data, html) {
			$("#jiancha_baogao").empty().html(html);
			$("#jiancha_2_table").treetable({ expandable: true,initialState : 'expanded' });
		});
	}else if(fenzu1!=-1){//一层分组
		
		laytplUrl(myurl + "/module/Inspection_report3.html",firstArr, function(data, html) {
			$("#jiancha_baogao").empty().html(html);
			$("#jiancha_3_table").treetable({ expandable: true,initialState : 'expanded' });
		});
	}else{//不分组
		laytplUrl(myurl + "/module/Inspection_report.html",firstArr, function(data, html) {
			$("#jiancha_baogao").empty().html(html);
			$("#jiancha_table").treetable({ expandable: true,initialState : 'expanded' });
		});
	}
}

// 检验简约报告分组规则加载

function addJyFenzuguize() {
	/*---------------------------简约模式----------------------------*/
	var html;
	var data = [ {"name" : "日期","value" : "lab20"}, {"name" : "仪器","value" : "bey03"}, {"name" : "缩写","value" : ""},
	             {"name" : "状态","value" : "lac11"}, {"name" : "检验时间","value" : "flab20"}, {"name" : "样本类型","value" : "abb02"},
	             {"name" : "打印","value" : "fprint"}, {"name" : "参考范围","value" : "lac15"}, {"name" : "结果","value" : "lac10"}, 
	             {"name" : "项目名称","value" : "bbx05"}, {"name" : "单位","value" : ""	} ]
	html = "<option value='-1'>-请选择-</option>";
	for (var i = 0; i < data.length; i++) {
		html += "<option value=" + data[i].value + ">";
		html += data[i].name;
		html += "</option>";
	}
	$(".jianyan_fenzu").empty().append(html);
	$("#jianyan_fenzu1").val("bey03");
	$("#jianyan_fenzu2").val("flab20");
	$("#jianyan_fenzu3").val("abb02");
	/*---------------------------经典模式----------------------------*/
	var jdhtml;
	var pram = [ {"name" : "仪器","value" : "bey03a"}, {"name" : "病区","value" : "bck01d"}, {"name" : "工作单位","value" : "baq03"},
	             {"name" : "病历号","value" : "vaa01"}, {"name" : "病人科室","value" : "bck01a"}, {"name" : "病人类别","value" : "bdp02"},
	             {"name" : "床号","value" : "lab16"}, {"name" : "生理特征","value" : "bes02"}, {"name" : "标本形态","value" : "lab42"}, 
	             {"name" : "诊断","value" : "lab18"}, {"name" : "执行科室","value" : "bck03c"}, {"name" : "样本条码","value" : ""	},
	             {"name" : "申请科室","value" : "bck03b"} , {"name" : "审核时间","value" : "lab53"}, {"name" : "检验人","value" : "bce03d"}
	             , {"name" : "核收人","value" : "bce03c"}, {"name" : "采样人","value" : "bce03a"}]
	jdhtml = "<option value='-1'>-请选择-</option>";
	for (var i = 0; i < pram.length; i++) {
		jdhtml += "<option value=" + pram[i].value + ">";
		jdhtml += pram[i].name;
		jdhtml += "</option>";
	}
	$(".jingdian_fenzu").empty().append(jdhtml);
	$("#jd_fenzu1").val("bey03a");
	$("#jd_fenzu2").val("bck03c");
	$("#jd_fenzu3").val("bce03d");
}



// 检验报告--------简约模式---------------------------------
function jianyanbaogao(LAB09) {
	var that = this;
	var url = rootUrl + "/patientcase/doctorconventionresult";
	var params = {};
	params.ACF01 = 1;
	params.LAB09 = LAB09;// 门诊号
	params.VAA03 = LAB09;
	params.currPage = 1;
	params.pageSize = 200;
	$.post(url, params, function(data) {
		var list = data.list;
//		that.laytplUrl(myurl + "/module/jianyan_jianyue.html", list,
//				function(data, html) {
//					$("#inspect_table").html(html);
//					$("#jianyue_table").treetable({
//						expandable : true
//					});
//					// $("#emr_app_file_list").treetable({ expandable: true });
//					// 根据分组规则排列
//				});
		$("#jysj").val(JSON.stringify(list));// 存储数据
		$("#jy_recombination").trigger("click");
//		jyRecombination();
	});
}
//排序
function bubbleSort(arr) {
    var i = arr.length, j;
    var tempExchangVal;
    while (i > 0) {
        for (j = 0; j < i - 1; j++) {
            if (arr[j] <arr[j + 1]) {
                tempExchangVal = arr[j];
                arr[j] = arr[j + 1];
                arr[j + 1] = tempExchangVal;
            }
        }
        i--;
    }
    return arr;
}
function diguiEvent(dataObj){
	
	var resultArr = [];// 总数组
	var fenzu1 = dataObj.fenzu1;
	var fenzu2 = dataObj.fenzu2;
	var fenzu3 = dataObj.fenzu3;
	/*组装fenzuArr,确保不管选哪个，都按字段的有效性排列*/
	var Arr=[fenzu1,fenzu2,fenzu3];
	var fenzuobj={};

	var arr = bubbleSort(Arr);

	
	for(var arrj=0;arrj<arr.length;arrj++){
		fenzuobj['fenzu'+(arrj+1)]=Arr[arrj];
	}
	
	
	if (fenzuobj.fenzu1!=-1) 
	{
		var fenzu1=	fenzuobj.fenzu1;	
		/*
		 * 获取三个参数名称数组
		 */
		var tempArr1 = [];
		$(dataObj).each(function(i, e) {
			tempArr1.push(e[fenzu1]);
		})
		var arr1 = tempArr1.unique2();//按照第一个参数分组
		
		var firstArr = [];//最终需要组装的数组
		for (var i = 0; i < arr1.length; i++) {
			var obj1 = {};
			obj1["data-tt-id"] = fenzu1 + i;
			obj1["name"] = arr1[i];
			/*
			 * 第一个参数分组后每个对象的children
			 */
			var temp1childrenArr = [];
			$(dataObj).each(function(j, ele) {
				if (ele[fenzu1] == arr1[i]) {
					ele["data-tt-id"] =obj1["data-tt-id"]+ fenzu1 + j ;//本身自己的继承id
					ele["data-tt-parent-id"] = obj1["data-tt-id"];//本身自己的继承的父id
					ele["parent-id"] =fenzu1 + i;//子类要继承的父id
					
					temp1childrenArr.push(ele);
				}
			});
			//----------------------------------------------first end
			
			if (fenzuobj.fenzu2!='-1') 
			{
				var fenzu2 =fenzuobj.fenzu2;
				var tempArr2 = [];
				for(var j = 0;j<temp1childrenArr.length;j++)
				{
					var e = temp1childrenArr[j];
					tempArr2.push(e[fenzu2]);
				}
				var arr2 = tempArr2.unique2();//按照第二个参数分组
				var sencondArr = [];//
				for(var k = 0;k<arr2.length;k++)
				{
					var obj2 = {};
					obj2["name"] = arr2[k];
					var temp2childrenArr = [];
					for(var m=0;m<temp1childrenArr.length;m++)
					{
						if(temp1childrenArr[m][fenzu2] == arr2[k])
						{
							obj2["data-tt-parent-id"]=temp1childrenArr[m]["parent-id"];//继承父类id
							obj2["data-tt-id"] = temp1childrenArr[m]['parent-id']+"-"+fenzu2 + k;//继承并创建自己的id
							var ele = temp1childrenArr[m];
							ele["data-tt-parent-id"] = obj2["data-tt-id"];//本身自己的继承id
							ele["data-tt-id"] =obj2["data-tt-id"]+"-"+fenzu2 + m;//本身自己的继承id
							ele["parent-id"] =obj2["data-tt-id"];//子类要继承的父id
							temp2childrenArr.push(ele);
						}
					}
					//-------------------------------------------second end /third 
					//------------------------------判断是否需要分第三组------------------
					if (fenzuobj.fenzu3!='-1') {
						var fenzu3 = fenzuobj.fenzu3;
						var tempArr3=[];
						for(var x=0;x<temp2childrenArr.length;x++)
						{
							var e = temp2childrenArr[x];
							tempArr3.push(e[fenzu3]);
						}
						var arr3 = tempArr3.unique2();//按照第三个参数分组
						var thirdArr=[];
						for(var y=0;y<arr3.length;y++)
						{
							var obj3 = {};
							obj3["name"] = arr3[y];
							var temp3childrenArr = [];
							for(var n=0;n<temp2childrenArr.length;n++)
							{
								if(temp2childrenArr[n][fenzu3]==arr3[y])
								{
									obj3["data-tt-parent-id"]=temp2childrenArr[n]["parent-id"];
									obj3["data-tt-id"] = temp2childrenArr[n]["parent-id"]+"-"+fenzu3 + y;
									var ele = temp2childrenArr[n];
									ele["data-tt-parent-id"] = obj3["data-tt-id"];
									ele["data-tt-id"] = obj3["data-tt-id"]+"-"+fenzu3+ n ;
									temp3childrenArr.push(ele);
								}
							}
							obj3['children'] = temp3childrenArr;
							thirdArr.push(obj3);
						}
						obj2['children'] = thirdArr;
					}else{
						obj2['children'] = temp2childrenArr;
					}
					//---------------------------------------------------------------------------------
					sencondArr.push(obj2);
				}
				
				obj1['children'] = sencondArr;
			}
			else//--------------第二次结束
				{
				
				obj1['children'] = temp1childrenArr;
				}
			
			firstArr.push(obj1);
		}
		}else{
		firstArr=dataObj;
	}
	
	//-------------------------------------------------------------all end
	if(dataObj.type=="jy_jianyue"){
		showResult(firstArr,fenzuobj);
	}else if(dataObj.type=="jy_jingdian"){
		jingdianShowResult(firstArr,fenzuobj);
	}else if(dataObj.type=="jc_baogao"){
		jianchaShowResult(firstArr,fenzuobj);
	}
}
//简约模式数据绑定模板
function showResult(firstArr,fenzuobj){
	var fenzu1=fenzuobj.fenzu1;
	var fenzu2=fenzuobj.fenzu2;
	var fenzu3=fenzuobj.fenzu3;
	if((fenzu1!=-1)&&(fenzu2!=-1)&&(fenzu3!=-1)){
		
		laytplUrl(myurl + "/module/jianyan_jianyue.html",firstArr, function(data, html) {
			$("#inspect_table").empty().html(html);
			$("#jianyue_table").treetable({ expandable: true,initialState : 'expanded' });
//		$(".jy_yq").hide();
		});
	}else if((fenzu1!=-1)&&(fenzu2!=-1)){
		
		laytplUrl(myurl + "/module/jianyan_jianyue2.html",firstArr, function(data, html) {
			$("#inspect_table").empty().html(html);
			$("#jianyue_table").treetable({ expandable: true,initialState : 'expanded' });
//		$(".jy_yq").hide();
		});
	}else if(fenzu1!=-1){
		
		laytplUrl(myurl + "/module/jianyan_jianyue3.html",firstArr, function(data, html) {
			$("#inspect_table").empty().html(html);
			$("#jianyue_table").treetable({ expandable: true,initialState : 'expanded' });
//		$(".jy_yq").hide();
		});
	}else{
		laytplUrl(myurl + "/module/jianyan_jianyue4.html",firstArr, function(data, html) {
			$("#inspect_table").empty().html(html);
			$("#jianyue_table").treetable({ expandable: true,initialState : 'expanded' });
			tableSetClick();
//		$(".jy_yq").hide();
		});
	}
	
}
//经典模式绑定模板
function jingdianShowResult(firstArr,fenzuobj){
	var fenzu1=fenzuobj.fenzu1;
	var fenzu2=fenzuobj.fenzu2;
	var fenzu3=fenzuobj.fenzu3;
	if((fenzu1!=-1)&&(fenzu2!=-1)&&(fenzu3!=-1)){//三层全有
		
		laytplUrl(myurl + "/module/jianyan_jingdian_left1.html",firstArr, function(data, html) {
			$("#jingdian_left_table").html(html);
			$("#jy_jingdian1_table").treetable({ expandable: true,initialState : 'expanded' });
		});
	}else if((fenzu1!=-1)&&(fenzu2!=-1)){ //两层数据
		
		laytplUrl(myurl + "/module/jianyan_jingdian_left2.html",firstArr, function(data, html) {
			$("#jingdian_left_table").html(html);
			$("#jy_jingdian2_table").treetable({ expandable: true,initialState : 'expanded' });
		});
	}else if(fenzu1!=-1){//一层数据
		
		laytplUrl(myurl + "/module/jianyan_jingdian_left3.html",firstArr, function(data, html) {
			$("#jingdian_left_table").html(html);
			$("#jy_jingdian1_table").treetable({ expandable: true,initialState : 'expanded' });
		});
	}else{//没有层级关系
		laytplUrl(myurl + "/module/jianyan_jingdian_left.html",firstArr, function(data, html) {
					$("#jingdian_left_table").empty().append(html);
					$("#jy_jingdian_table").treetable({ expandable: true,initialState : 'expanded' });
				});
	
	}
	
}
//经典table tr双击获取常规数据
function addJdChanggui(LAB01){//仪器id
	/*--------- 常规数据--------------*/
		var that = this;
		var url = rootUrl + "/patientcase/conventionresult";
		var params = {};
		params.LAB01 = LAB01;// 检验样本id
		params.currPage = 1;
		params.pageSize = 200;
		$.post(url, params, function(data) {
			var list = data.list;
			that.laytplUrl(myurl + "/module/jy_jd_changgui.html",
					list, function(data, html) {
						$("#jy_jd_tuxCg").empty().append(html);
					});
		});
	
}
// 检验简约根据分组规则重组table
function jyRecombination() {
	if(($("#jysj").val())&&($("#jysj").val()!="[]")){
	var dataObj = JSON.parse($("#jysj").val());
	var fenzu1 = $("#jianyan_fenzu1").val();
	var fenzu2 = $("#jianyan_fenzu2").val();
	var fenzu3 = $("#jianyan_fenzu3").val();
	dataObj=$.extend(dataObj,{"fenzu1":fenzu1},{"fenzu2":fenzu2},{"fenzu3":fenzu3},{"type":"jy_jianyue"});
	diguiEvent(dataObj)	;
	}else{
		$("#inspect_table").empty().html("暂无数据");
//		layer.msg("暂无数据！" ,{time:2000,icon:0});
	}
}
//经典根据分组规则重组table
function jyJingdianRecombination(){
	if(($("#jy_jdsj").val())&&($("#jy_jdsj").val()!="[]")){
		var dataObj = JSON.parse($("#jy_jdsj").val());
		var fenzu1 = $("#jd_fenzu1").val();
		var fenzu2 = $("#jd_fenzu2").val();
		var fenzu3 = $("#jd_fenzu3").val();
		dataObj=$.extend(dataObj,{"fenzu1":fenzu1},{"fenzu2":fenzu2},{"fenzu3":fenzu3},{"type":"jy_jingdian"});
		diguiEvent(dataObj)	;
		
	}else{
		$("#jy_jd_tuxCg").empty();
		$("#jingdian_left_table").empty().append("暂无数据！");
//		layer.msg("暂无数据！" ,{time:2000,icon:0});
	}
}
/*function jyRecombination() {
	var dataObj = JSON.parse($("#jysj").val());
//	$("#jy_recombination").on("click",function() {
	var resultArr = [];// 总数组
	var fenzu1 = $("#jianyan_fenzu1").val();
	var fenzu2 = $("#jianyan_fenzu2").val();
	var fenzu3 = $("#jianyan_fenzu3").val();
	
	 * 获取三个参数名称数组
	 
	var tempArr1 = [];
	$(dataObj).each(function(i, e) {
		tempArr1.push(e[fenzu1]);
	})
	var arr1 = tempArr1.unique2();//按照第一个参数分组
	
	var firstArr = [];//最终需要组装的数组
	for (var i = 0; i < arr1.length; i++) {
		var obj1 = {};
		obj1["data-tt-id"] = "yiqi" + i;
		obj1["name"] = arr1[i];
		
		 * 第一个参数分组后每个对象的children
		 
		var temp1childrenArr = [];
		$(dataObj).each(function(j, ele) {
			if (ele[fenzu1] == arr1[i]) {
				ele["data-tt-id"] = "yiqi" + i ;
				temp1childrenArr.push(ele);
			}
		});
		//----------------------------------------------first end
		var tempArr2 = [];
		for(var j = 0;j<temp1childrenArr.length;j++)
		{
			var e = temp1childrenArr[j];
			tempArr2.push(e[fenzu2]);
		}
		var arr2 = tempArr2.unique2();//按照第二个参数分组
		var sencondArr = [];//
		for(var k = 0;k<arr2.length;k++)
		{
			var obj2 = {};
			obj2["name"] = arr2[k];
			var temp2childrenArr = [];
			for(var m=0;m<temp1childrenArr.length;m++)
			{
				if(temp1childrenArr[m][fenzu2] == arr2[k])
				{
					obj2["data-tt-parent-id"]=temp1childrenArr[m]["data-tt-id"];
					obj2["data-tt-id"] = temp1childrenArr[m]['data-tt-id']+"-shijian" + k;
					var ele = temp1childrenArr[m];
					ele["data-tt-parent-id"] = temp1childrenArr[m]["data-tt-id"];
					ele["data-tt-id"] =temp1childrenArr[m]["data-tt-id"]+"-shijian" + k;
					temp2childrenArr.push(ele);
				}
			}
			//-------------------------------------------second end /third 
			var tempArr3=[];
			for(var x=0;x<temp2childrenArr.length;x++)
			{
				var e = temp2childrenArr[x];
				tempArr3.push(e[fenzu3]);
			}
			var arr3 = tempArr3.unique2();//按照第三个参数分组
			var thirdArr=[];
			for(var y=0;y<arr3.length;y++)
			{
				var obj3 = {};
				obj3["name"] = arr3[y];
				var temp3childrenArr = [];
				for(var n=0;n<temp2childrenArr.length;n++)
				{
					if(temp2childrenArr[n][fenzu3]==arr3[y])
					{
						obj3["data-tt-parent-id"]=temp2childrenArr[n]["data-tt-id"];
						obj3["data-tt-id"] = temp2childrenArr[n]["data-tt-id"]+"-yangben" + y;
						var ele = temp2childrenArr[n];
						ele["data-tt-parent-id"] = temp2childrenArr[n]["data-tt-id"]+"-yangben" + y;
						ele["data-tt-id"] = temp2childrenArr[n]["data-tt-id"]+"-yangben" +"-000"+ y ;
						temp3childrenArr.push(ele);
					}
				}
				obj3['children'] = temp3childrenArr;
				thirdArr.push(obj3);
			}
			
			obj2['children'] = thirdArr;
			sencondArr.push(obj2);
		}
		
		obj1['children'] = sencondArr;
		firstArr.push(obj1);
	}
	
	
	//-------------------------------------------------------------all end
	laytplUrl(myurl + "/module/jianyan_jianyue.html",firstArr, function(data, html) {
		$("#inspect_table").html(html);
		$("#jianyue_table").treetable({ expandable: true,initialState : 'expanded' });
//									$(".jy_yq").hide();
	});
//					});
	
}
*//* ---------------------------检验报告--------------------经典模式------------------------ */
/*----------- 左边数据表格---------*/
function jianyanJingdian(LAB09) {
	var that = this;
	var url = rootUrl + "/patientcase/viewinspectionreport";
	var params = {};
	params.ACF01 = 1;
	params.LAB09 = LAB09;// 门诊号
	params.VAA03 = LAB09;
	params.currPage = 1;
	params.pageSize = 200;
	$.post(url, params, function(data) {
		var list = data.list;
		$("#jy_jdsj").val(JSON.stringify(list));// 存储数据
		$("#jy_jingdian_search").trigger("click");
		
	});
}
/*--------- 图形数据--------------*/
function jianyanJingdianTx(LAB09) {
	var that = this;
	var url = rootUrl + "/patientcase/inspectionreportimage";
	var params = {};
	params.LAB01 = LAB01;// 检验样本id
	params.BEY01 = BEY01;// 仪器id
	params.currPage = 1;
	params.pageSize = 200;
	$.post(url, params, function(data) {
		var list = data.list;
		that.laytplUrl(myurl + "/module/jianyan_jingdian_left.html",
				list, function(data, html) {
					$("#jingdian_left_table").empty().append(html);
				});
	});
}

// 新开页面：
function newOrder() {
	var that = this;
	$("#newpage").on("click",function() {
				var vaa01 = $("#vaa01").val();
				if (isOwnchose) {
					var vac01 = $("#vac01").val();
					var vaa05 = $("#vaa05").text();
					var age = $("#age").text();
					var index = layer.open({
						type : 2,
						title : '新开医嘱  ' + vaa05 + "  " + age,
						area : [ "95%", "95%" ],
						shade : 0.3,
						maxmin : true,
						content :myurl+"/neworder.jsp?vaa01="+vaa01+"&vac01="+vac01+"&bck01="+bck01+"&vaa05="+vaa05+"&age="+age,
//						content : myurl + "/neworder.jsp?vaa01=" + vaa01
//								+ "&vac01=" + vac01 + "&bck01=" + bck01
//								+ "&vaa05='" + vaa05 + "'&age='" + age + "'"

					});
				} else {
					layer.msg("请选择就诊病人", {
						time : 2000,
						icon : 0,
						skin: 'layui-layer-msg0'
					});
				}

			});
}






// 新开更多页面加载

function patientMoreType() {
	var data = [ {
		"name" : "检查",
		"value" : "jc"
	}, {
		"name" : "检验",
		"value" : "jy"
	}, {
		"name" : "中药处方",
		"value" : "zy"
	}, {
		"name" : "西药处方",
		"value" : "xy"
	}, {
		"name" : "急诊",
		"value" : "jz"
	}, {
		"name" : "儿童",
		"value" : "et"
	}, {
		"name" : "毒麻",
		"value" : "dm"
	}, {
		"name" : "精一",
		"value" : "jyi"
	}, {
		"name" : "精二",
		"value" : "jer"
	}, {
		"name" : "手术",
		"value" : "ss"
	}, {
		"name" : "治疗",
		"value" : "zl"
	}, {
		"name" : "卫生材料",
		"value" : "wscl"
	} ]

	for (var i = 0; i < data.length; i++) {
		var html = "<li><label class='checkbox-inline'> <input type='checkbox' id='' value='' >";
		html += data[i].name;
		html += "</label></li>";
		$("#patient_more").append(html);
	}

}

// 根据医嘱类型查询医嘱记录
function changeAdcive() {
	var searchStr = $("#bdaSearch>option:selected").attr("id");
	if (searchStr != "") {
		$("#advice_table tbody").hide()
				.filter(":contains('" + searchStr + "')").show();
	} else {
		$("#advice_table tbody").show();
	}
}

// 根据医嘱状态查询医嘱（前端实现）
function checkboxEvent1()
{
	$('#vaf10_1').on('ifChecked', function(event)
	{
		$("#advice_table tbody tr").find("td:eq(2)").filter(":contains('新开')").parents("tbody").show();
	});
	$('#vaf10_1').on('ifUnchecked', function(event)
	{
		$("#advice_table tbody tr").find("td:eq(2)").filter(":contains('新开')").parents("tbody").hide();
	});

}
// 发送
function checkboxEvent8()
{
	$('#vaf10_8').on('ifChecked', function(event)
	{
		$("#advice_table tbody tr").find("td:eq(2)").filter(":contains('已发送')").parents("tbody").show();
	});
	$('#vaf10_8').on('ifUnchecked', function(event)
	{
		$("#advice_table tbody tr").find("td:eq(2)").filter(":contains('已发送')").parents("tbody").hide();
	});

}

function checkboxEvent4()
{
	// 作废
	$('#vaf10_4').on('ifChecked', function(event)
	{
		$("#advice_table tbody tr").find("td:eq(2)").filter(":contains('医嘱退费')").parents("tbody").show();
	});
	$('#vaf10_4').on('ifUnchecked', function(event)
	{
		$("#advice_table tbody tr").find("td:eq(2)").filter(":contains('医嘱退费')").parents("tbody").hide();
	});
}
// 医嘱记录操作切换
function yizhuOperation()
{
	$("#patient_operation .listMenu").on("click", function()
	{
		var listNum
		$(this).addClass("listDownLine").siblings().removeClass("listDownLine");
		var listNum = $(this).index();
		$("#yizhujilu_content .yizhu_content").eq(listNum).removeClass("hidden").siblings().addClass("hidden");
	});
}
// 医嘱记录更多操作
function moreOperation() {
	$("#patient_operation .moreCont").on("click", function() {
		if ($("#yizhujilu_content").css("display") == "none") {
			$("#table_list").addClass("hidden");
			$("#yizhujilu_content").removeClass("hidden");
			$("#patient_operation .moreCont").text("折叠");
		} else {
			$("#table_list").removeClass("hidden");
			$("#yizhujilu_content").addClass("hidden");
			$("#patient_operation .moreCont").text("展开");
		}

	})
}

// 医嘱单选定，并查看医嘱信息
function otherProperties()
{
	$(".innerHead").on("click",function()
			{
				var cbm01 = $(this).attr("data-cbm01list");
				var data_info = $($(this).parents("tbody").find(".yizhu_details")[0]).attr("data-info");
				var vaf10 = JSON.parse(data_info).vaf10;
				debugger;
				var vaf01 = JSON.parse(data_info).vaf01;
				if(vaf10==1)
				{
					//1349
					$.post(rootUrl+"/doctoradvice/doctoradvicepriceinfo",{"lCBM01":cbm01,"ABC02":$("abc02").text()},function(data)
							{
						vbd_jqgrid(data.list);
						$("#vaf1Fasongjilu_table").empty();
							});
				}
				else if(vaf10==8)
				{
					//1402
					$.post(rootUrl+"/doctoradvice/doctoradvicedetail",{"lCBM01":cbm01},function(data)
							{
						vbd_jqgrid(data.list);
							});
					//1405 医嘱单发送记录
					$.post(rootUrl+"/doctoradvice/sendadvicehistory",{"lCBM01":cbm01},function(data)
							{
						var list = data.list;
						$("#vaf1Fasongjilu_table").empty();
			    		for(var i= 0;i<list.length;i++)
			    		{
			    			var td1 = $("<td>"+(list[i]["fvbi15"]?list[i]["fvbi15"]:'未结账')+"</td>");
			    			var td2 = $("<td>"+(list[i]["vbi09"]?list[i]["vbi09"]:'')+"</td>");
			    			var td3 = $("<td>"+(list[i]["nbby05"]?list[i]["nbby05"]:'')+"</td>");
			    			var td5 = $("<td>"+(list[i]["vbi07"]?list[i]["vbi07"]:'')+"</td>");
			    			var td6 = $("<td>"+(list[i]["bck03"]?list[i]["bck03"]:'')+"</td>");
			    			var td7 = $("<td>"+(list[i]["bce03a"]?list[i]["bce03a"]:'')+"</td>");
			    			var td8 = $("<td>"+(list[i]["fvbi13"]?list[i]["fvbi13"]:'')+"</td>");
			    			var td9 = $("<td>"+(list[i]["vai04"]?list[i]["vai04"]:'')+"</td>");
			    			var td10 = $("<td>"+(list[i]["vbi21"]?list[i]["vbi21"]:'')+"</td>");
			    			var tr = $("<tr></tr>");
			    			tr.append(td1);
			    			tr.append(td2);
			    			tr.append(td3);
			    			tr.append(td5);
			    			tr.append(td6);
			    			tr.append(td7);
			    			tr.append(td8);
			    			tr.append(td9);
			    			tr.append(td10);
			    			$("#vaf1Fasongjilu_table").append(tr);
			    		}
							});
				}
				//7501 医嘱单处方属性
				var params = {};
				params.iaa01 = 0;
				params.acf01 = 1;
				debugger;
				params.vaf01 = vaf01;
			    	$.post(rootUrl+"/doctoradvice/doctoradviceprescriptionproperty",params,function(data){
			    		var list = data.list;
			    		$("#chufangshuxing_table tbody").empty();
			    		for(var i= 0;i<list.length;i++)
			    		{
			    			var td1 = $("<td>"+(list[i]["cbm07"]?list[i]["cbm07"]:'')+"</td>");
			    			var td2 = $("<td>"+(list[i]["bjw02"]?list[i]["bjw02"]:'')+"</td>");
			    			var td3 = $("<td>"+(list[i]["iai03"]?list[i]["iai03"]:'')+"</td>");
			    			var tr = $("<tr></tr>");
			    			tr.append(td1);
			    			tr.append(td2);
			    			tr.append(td3);
			    			$("#chufangshuxing_table tbody").append(tr);
			    		}
			    	});
				//1176 医嘱单处方诊断
				var url = rootUrl + "/doctoradvice/doctordiagnosis";
				var params1 = {};
				params1.lVAF01 = vaf01;
				params1.acf01 = 1;
				$.post(url, params1, function(data) {
					debugger;
					var list = data.list;
					$("#chufangzhenduan_table").empty();
					for (var i = 0; i < list.length; i++) {
						var tr = $("<tr></tr>");
						var td2 = $("<td></td>");
						var td22 = $("<td>" + (list[i]["vao15"]?list[i]["vao15"]:'') + "</td>");
						tr.append(td2);
						tr.append(td22);
						$("#chufangzhenduan_table").append(tr);
					}
				})
			});
	$(".yizhu_details").on("click", function(e)
	{
		/*
		 * if(e.target.tagName=="INPUT"){ return; }
		 */
		$(this).addClass("choseedTr").parent().siblings().find(".yizhu_details").removeClass("choseedTr");
//		$(this).parents("tbody").find(".innerHead").find("input[type='checkbox']").prop("checked",true); //自己的医嘱单选中
//		$(this).parents("tbody").siblings().find(".innerHead").find("input[type='checkbox']").prop("checked",false); //其他的医嘱单取消选中
		
		var dataStr = $(this).attr("data-info");
		var dataObj = JSON.parse(dataStr);
		cbm01 = dataObj.cbm01;
//		printAdvice(dataObj.bda01,dataObj.vaf10);//vaf10 判断是否是医嘱单状态
//		if(dataObj.vaf10=='8'){//点击表格的医嘱单某个tr,加载打印格式
//			printAdvice(dataObj.bda01);
//		}else{
//			$("#advice_print").empty();
//		}
		//医嘱计价
		vbdInfo(dataObj);
		// 处方诊断
		chufangzhenduan(dataObj.cbm01);
		// 处方性质
		chufangshuxing(dataObj.vaf01);
		// 手术人员安排
		shouShuRenYuanAnpai(dataObj.vaf01);
		// 医嘱发送记录
		/*var bda01 = dataObj.bda01;
		var vaf01 = dataObj.vaf01;
		if (bda01 == "3" || bda01 == "8" || bda01 == "S")
		{
			vaf1Fasongjilu3(dataObj.vaf01);
		}
		else if (bda01 == "1" || bda01 == "2")
		{
			vaf1Fasongjilu1(dataObj.vaf01);
		}
		else
		{
			vaf1FasongjiluOther(dataObj.vaf01);
		}*/
		//1405 医嘱单发送记录
		$.post(rootUrl+"/doctoradvice/sendadvicehistory",{"lCBM01":cbm01},function(data)
				{
			var list = data.list;
			$("#vaf1Fasongjilu_table").empty();
    		for(var i= 0;i<list.length;i++)
    		{
    			var td1 = $("<td>"+(list[i]["fvbi15"]?list[i]["fvbi15"]:'未结账')+"</td>");
    			var td2 = $("<td>"+(list[i]["vbi09"]?list[i]["vbi09"]:'')+"</td>");
    			var td3 = $("<td>"+(list[i]["nbby05"]?list[i]["nbby05"]:'')+"</td>");
    			var td5 = $("<td>"+(list[i]["vbi07"]?list[i]["vbi07"]:'')+"</td>");
    			var td6 = $("<td>"+(list[i]["bck03"]?list[i]["bck03"]:'')+"</td>");
    			var td7 = $("<td>"+(list[i]["bce03a"]?list[i]["bce03a"]:'')+"</td>");
    			var td8 = $("<td>"+(list[i]["fvbi13"]?list[i]["fvbi13"]:'')+"</td>");
    			var td9 = $("<td>"+(list[i]["vai04"]?list[i]["vai04"]:'')+"</td>");
    			var td10 = $("<td>"+(list[i]["vbi21"]?list[i]["vbi21"]:'')+"</td>");
    			var tr = $("<tr></tr>");
    			tr.append(td1);
    			tr.append(td2);
    			tr.append(td3);
    			tr.append(td5);
    			tr.append(td6);
    			tr.append(td7);
    			tr.append(td8);
    			tr.append(td9);
    			tr.append(td10);
    			$("#vaf1Fasongjilu_table").append(tr);
    		}
				});
		
		// 加载打印医嘱列表

		// printAdvice(bda01);
	})

}
// 打印选中医嘱单，添加打印类型
function printCheckedEvent(){
	if ($(".innerHead td input:checked").length <= 0)
	{
		layer.msg("请勾选要打印的医嘱单",
		{
		time : 2000,
		icon : 0,
		skin: 'layui-layer-msg0'
		});
		return;
	}
	else if($(".innerHead td input:checked").length > 1)
	{
		layer.msg("只能勾选一个医嘱单",
				{
				time : 2000,
				icon : 0,
				skin: 'layui-layer-msg0'
				});
				return;
	}
	else
	{
		var dataStr=$($(".innerHead td input:checked").parents("tbody").find(".yizhu_details")[0]).attr("data-info");
		var dataObj = JSON.parse(dataStr);
		cbm01 = dataObj.cbm01;
		var bda01 = dataObj.bda01;
		var vaf10 = dataObj.vaf10;
		if(vaf10!=8)
		{
			layer.msg("请先发送医嘱单",
					{
					time : 2000,
					icon : 0,
					skin: 'layui-layer-msg0'
					});
					return;
		}
		printAdvice(bda01,vaf10);//vaf10 判断是否是医嘱单状态
	}
}

// 加载打印格式下拉列表
function printAdvice(bda01,vaf10) {
	switch (bda01) {
	case "1":
		rid = 24;
		break;
	case "8":
		rid = 25;
		break;
	case "E":
		rid = 22;
		break;
	case "L":
		rid = 23;
		break;
	case "S":
		rid = 28;
		break;
	case "T":
		rid = 190;
		break;
	}
	var myAjax = $.ajax({
		url : printUrl + "/printtemprest/findListByRid/" + rid,
		type : "get",
		async : true,
		dataType : "json",
		traditional : true,
		// async: false,//根据报表ID，定位打印格式
		timeout : 1000,
		success : function(data) {
//			$("#advice_print").empty();
			var html;
			for (var i = 0; i < data.length; i++) {
				var obj = {};
				obj.vaf10 = vaf10;
				obj.id = data[i]['id'];
				if (data[i]['xdefault'] == "1") {
					 html = '<option data-info='+JSON.stringify(obj)+'>'+data[i]['name']+'</option>';
//					var li = $("<li onclick='print1(" + data[i]['id'] + ")'>")
//							.append($("<a herf='#'>").text(data[i]['name'] + "-打印预览"));
//					var li1 = $("<li onclick='print(" + data[i]['id'] + ")'>")
//							.append($("<a herf='#'>").text(data[i]['name']));
//					$("#advice_print").append(li);
//					$("#advice_print").append(li1);
				} else {
					 html = '<option data-info='+JSON.stringify(obj)+'>'+data[i]['name']+'</option>';
//					var li = $("<li onclick='print1(" + data[i]['id'] + ")'>")
//							.append(
//									$("<a herf='#'>").text(
//											data[i]['name'] + "-打印预览"));
//					var li1 = $("<li onclick='print(" + data[i]['id'] + ")'>")
//							.append($("<a herf='#'>").text(data[i]['name']));
//					$("#advice_print").append(li);
//					$("#advice_print").append(li1);
				}
				$("#advice_print").empty().append(html);
			}
		},
		error : function(XMLHttpRequest, textStatus, errorThrown) {
			layer.msg('打印服务器连接失败！', {
				time : 2000,
				icon : 2,
				skin: 'layui-layer-msg2'
			});
		}
	});

}
//选择打印格式
function chosePrintType(){
	 var e=arguments.callee.caller.arguments[0]||event; 
	 if (e && e.stopPropagation) { 
	  // this code is for Mozilla and Opera
	  e.stopPropagation(); 
	 } else if (window.event) { 
	  // this code is for IE 
	  window.event.cancelBubble = true; 
	 } 
}

// 医嘱打印预览
function print1() {
	var datastr = $("#advice_print option:selected").attr("data-info");
	if(datastr){
		var dataObj = JSON.parse(datastr);
		var id = dataObj.id;
		var vaf10 = dataObj.vaf10;
		if(vaf10 == '8'){
			var url = printUrl + "/printtoolrest/printToPdfView/" + id + "?cbm01="
			+ cbm01;
			window.open(url);
		}else{
			if(vaf10 == '1'){
				layer.alert("请先发送医嘱单！");
			}else if(vaf10 == '4'){
				layer.alert("医嘱已作废，请重开！");
			}
		}
	}else{
		layer.msg("请选择打印的医嘱单！",{time:2000,icon:0,skin: 'layui-layer-msg0'});
	}
}


// 加载病人的处方诊断信息
function chufangzhenduan(vaf01) {
	var url = rootUrl + "/doctoradvice/doctordiagnosis";
	var params = {};
	params.lVAF01 = vaf01;
	params.acf01 = 1;
	$.post(url, params, function(data) {
		var list = data.list;
		var tr = $("<tr></tr>");
		$("#chufangzhenduan_table").empty();
		for (var i = 0; i < list.length; i++) {
			var tr = $("<tr></tr>");
			var td2 = $("<td></td>");
			var td22 = $("<td>" + (list[i]["vao15"]?list[i]["vao15"]:'') + "</td>");
			tr.append(td2);
			tr.append(td22);
			$("#chufangzhenduan_table").append(tr);
		}
	})
}
    
    
    
    //加载病人处方属性
    function chufangshuxing(vaf01)
    {
    	var url = rootUrl + "/doctoradvice/doctoradviceprescriptionproperty";;
    	var params= {};
    	params.iaa01 = 0;
    	params.acf01 = 1;
    	params.vaf01 = vaf01;
    	$.post(url,params,function(data){
    		var list = data.list;
    		$("#chufangshuxing_table tbody").empty();
    		for(var i= 0;i<list.length;i++)
    		{
    			var td1 = $("<td>"+(list[i]["cbm07"]?list[i]["cbm07"]:'')+"</td>");
    			var td2 = $("<td>"+(list[i]["bjw02"]?list[i]["bjw02"]:'')+"</td>");
    			var td3 = $("<td>"+(list[i]["iai03"]?list[i]["iai03"]:'')+"</td>");
    			var tr = $("<tr></tr>");
    			tr.append(td1);
    			tr.append(td2);
    			tr.append(td3);
    			$("#chufangshuxing_table tbody").append(tr);
    		}
    	});
    }
    
    //加载手术人员安排
    function shouShuRenYuanAnpai(vaf01)
    {
    	var url = rootUrl + "/doctoradvice/queryoperationscheduled";;
    	var params= {};
    	params.VAF01 = vaf01;
    	$.post(url,params,function(data){
    		var list = data.list;
    		$("#shoushurenyuananpai_table tbody").empty();
    		for(var i= 0;i<list.length;i++)
    		{
    			var td1 = $("<td>"+list[i]["ace02"]+"</td>");
    			var td2 = $("<td>"+list[i]["bce02"]+"</td>");
    			var td3 = $("<td>"+list[i]["bce03"]+"</td>");
    			var tr = $("<tr></tr>");
    			tr.append(td1);
    			tr.append(td2);
    			tr.append(td3);
    			$("#shoushurenyuananpai_table").append(tr);
    		}
    	});
    }
    
    //医嘱发送记录(草药和手术)
    function vaf1Fasongjilu3(vaf01)
    {
    	var url = rootUrl + "/sendadvicehistory/herbandoperationsendhistory";;
    	var params= {};
    	params.lVAFID = vaf01;
    	$.post(url,params,function(data){
    		var list = data.list;
    		$("#vaf1Fasongjilu_table").empty();
    		for(var i= 0;i<list.length;i++)
    		{
    			var td1 = $("<td>"+(list[i]["fvbi15"]?list[i]["fvbi15"]:'未结账')+"</td>");
    			var td2 = $("<td>"+(list[i]["vbi09"]?list[i]["vbi09"]:'')+"</td>");
    			var td3 = $("<td>"+(list[i]["nbby05"]?list[i]["nbby05"]:'')+"</td>");
    			var td5 = $("<td>"+(list[i]["vbi07"]?list[i]["vbi07"]:'')+"</td>");
    			var td6 = $("<td>"+(list[i]["bck03"]?list[i]["bck03"]:'')+"</td>");
    			var td7 = $("<td>"+(list[i]["bce03a"]?list[i]["bce03a"]:'')+"</td>");
    			var td8 = $("<td>"+(list[i]["fvbi13"]?list[i]["fvbi13"]:'')+"</td>");
    			var td9 = $("<td>"+(list[i]["vbi05"]?list[i]["vbi05"]:'')+"</td>");
    			var tr = $("<tr></tr>");
    			tr.append(td1);
    			tr.append(td2);
    			tr.append(td3);
    			tr.append(td5);
    			tr.append(td6);
    			tr.append(td7);
    			tr.append(td8);
    			tr.append(td9);
    			$("#vaf1Fasongjilu_table").append(tr);
    		}
    	});
    }
    
    //医嘱发送记录(西药)
    function vaf1Fasongjilu1(vaf01)
    {
    	var url = rootUrl + "/sendadvicehistory/sendpharmacyhistory";;
    	var params= {};
    	params.lVAF01 = vaf01;
    	params.lVAF01A = vaf01;
    	$.post(url,params,function(data){
    		var list = data.list;
    		$("#vaf1Fasongjilu_table").empty();
    		for(var i= 0;i<list.length;i++)
    		{
    			var td1 = $("<td>"+(list[i]["fvbi15"]?list[i]["fvbi15"]:'')+"</td>");
    			var td2 = $("<td>"+(list[i]["vbi09"]?list[i]["vbi09"]:'')+"</td>");
    			var td3 = $("<td>"+(list[i]["nbby05"]?list[i]["nbby05"]:'')+"</td>");
    			var td5 = $("<td>"+(list[i]["vbi07"]?list[i]["vbi07"]:'')+"</td>");
    			var td6 = $("<td>"+(list[i]["bck03"]?list[i]["bck03"]:'')+"</td>");
    			var td7 = $("<td>"+(list[i]["bce03a"]?list[i]["bce03a"]:'')+"</td>");
    			var td8 = $("<td>"+(list[i]["fvbi13"]?list[i]["fvbi13"]:'')+"</td>");
    			var td9 = $("<td>"+(list[i]["vbi01"]?list[i]["vbi01"]:'')+"</td>");
    			var tr = $("<tr></tr>");
    			tr.append(td1);
    			tr.append(td2);
    			tr.append(td3);
    			tr.append(td5);
    			tr.append(td6);
    			tr.append(td7);
    			tr.append(td8);
    			tr.append(td9);
    			$("#vaf1Fasongjilu_table").append(tr);
    		}
    	});
    }
    
    
    //医嘱发送记录(其它)
    function vaf1FasongjiluOther(vaf01)
    {
    	var url = rootUrl + "/sendadvicehistory/otheradvicesendhistory";
    	var params= {};
    	params.VAF01 = vaf01;
    	$.post(url,params,function(data){
    		var list = data.list;
    		$("#vaf1Fasongjilu_table").empty();
    		for(var i= 0;i<list.length;i++)
    		{
    			var td1 = $("<td>"+(list[i]["fvbi15"]?list[i]["fvbi15"]:'')+"</td>");
    			var td2 = $("<td>"+(list[i]["vbi09"]?list[i]["vbi09"]:'')+"</td>");
    			var td3 = $("<td>"+(list[i]["nbby05"]?list[i]["nbby05"]:'')+"</td>");
    			var td5 = $("<td>"+(list[i]["vbi07"]?list[i]["vbi07"]:'')+"</td>");
    			var td6 = $("<td>"+(list[i]["bck03"]?list[i]["bck03"]:'')+"</td>");
    			var td7 = $("<td>"+(list[i]["bce03a"]?list[i]["bce03a"]:'')+"</td>");
    			var td8 = $("<td>"+(list[i]["fvbi13"]?list[i]["fvbi13"]:'')+"</td>");
    			var td9 = $("<td>"+(list[i]["vbi05"]?list[i]["vbi05"]:'')+"</td>");
    			var tr = $("<tr></tr>");
    			tr.append(td1);
    			tr.append(td2);
    			tr.append(td3);
    			tr.append(td5);
    			tr.append(td6);
    			tr.append(td7);
    			tr.append(td8);
    			tr.append(td9);
    			$("#vaf1Fasongjilu_table").append(tr);
    		}
    	});
    }
    
    
    
    //根据医嘱状态查询医嘱（前端实现）
    function checkboxEvent1()
	{
    	$('#vaf10_1').on('ifChecked', function(event){
    		$("#advice_table tbody tr").find("td:eq(2)").filter(":contains('新开')").parents("tbody").show(); 
  		});
    	$('#vaf10_1').on('ifUnchecked', function(event){
    		$("#advice_table tbody tr").find("td:eq(2)").filter(":contains('新开')").parents("tbody").hide();
  		});
		
	}
  //发送
    function checkboxEvent8()
    {
    	$('#vaf10_8').on('ifChecked', function(event){
    		$("#advice_table tbody tr").find("td:eq(2)").filter(":contains('已发送')").parents("tbody").show(); 
  		});
    	$('#vaf10_8').on('ifUnchecked', function(event){
    		$("#advice_table tbody tr").find("td:eq(2)").filter(":contains('已发送')").parents("tbody").hide();  
  		});
    	
    }
    
    function checkboxEvent4()
    {
    	//作废
    	$('#vaf10_4').on('ifChecked', function(event){
    		$("#advice_table tbody tr").find("td:eq(2)").filter(":contains('医嘱退费')").parents("tbody").show();  
  		});
    	$('#vaf10_4').on('ifUnchecked', function(event){
    		$("#advice_table tbody tr").find("td:eq(2)").filter(":contains('医嘱退费')").parents("tbody").hide();  
  		});
    }
   //医嘱记录操作切换
    function yizhuOperation(){
    	$("#patient_operation .listMenu").on("click",function() {
    				var listNum
    				$(this).addClass("listDownLine").siblings().removeClass("listDownLine");
    				var listNum = $(this).index();
    				$("#yizhujilu_content .yizhu_content").eq(listNum).removeClass("hidden").siblings().addClass("hidden");
    			});
    }

    
  
    
    //加载打印格式下拉列表
    /*function printAdvice(bda01)
    {
    	switch(bda01)
    	{
    		case "1" : rid = 24;break;
    		case "8" : rid = 25;break;
    		case "E" : rid = 22;break;
    		case "L" : rid = 23;break;
    		case "S" : rid = 28;break;
    		case "T" : rid = 190;break;
    	}
    	 var myAjax=$.ajax({
            url: printUrl+"/printtemprest/findListByRid/"+rid,
            type: "get",
            dataType: "json",
            traditional: true,
           // async: false,//根据报表ID，定位打印格式
            timeout:1000,
            success: function (data) 
            {
            	$("#advice_print").empty();
            	for(var i =0;i<data.length;i++)
            	{
            		if(data[i]['xdefault']=="1")
            		{
            			var li = $("<li onclick='print1("+data[i]['id']+")'>").append($("<a herf='#'>").text(data[i]['name']+"-打印预览"));
            			var li1 = $("<li onclick='print("+data[i]['id']+")'>").append($("<a herf='#'>").text(data[i]['name']));
            			$("#advice_print").append(li);
            			$("#advice_print").append(li1);
            		}
            		else
            		{
            			var li = $("<li onclick='print1("+data[i]['id']+")'>").append($("<a herf='#'>").text(data[i]['name']+"-打印预览"));
            			var li1 = $("<li onclick='print("+data[i]['id']+")'>").append($("<a herf='#'>").text(data[i]['name']));
            			$("#advice_print").append(li);
            			$("#advice_print").append(li1);
            		}
            	}
            },
            error: function(XMLHttpRequest, textStatus, errorThrown)
            {
            	if (textStatus=='timeout') {
					layer.msg('打印服务器连接失败！', {
						time : 2000,
						icon : 3
					});
				}
            	else
            	{
            		layer.msg(textStatus, {
						time : 2000,
						icon : 3
					});
            	}
            }
        });

    }*/
    
    
    
    //入院通知单打印预览
    function print2(id,vac01)
    {
//    	var url = printUrl+"/printtoolrest/printToPdfView/"+id+"?vac01="+vac01;
//    	window.open(url);
    	
    	var url = printUrl+"/printtoolrest/printToPdf/"+id+"?vac01="+vac01;
    	layer.closeAll();         // 打印前先关闭已经打开 layer 弹框
        layer.open({
            type: 2,
            title:false,          // title 不显示
            closeBtn: 0,          // 不显示  layer 弹框关闭按钮
            shadeClose: false,
            shade: false,
            area: ['0%', '0%'],   //在页面上不显示
            content: url,         //iframe的url,
            success:function(){
                // $("#cover").addClass("hidden");  //去掉遮罩层
                console.log($("#icon"));
            }
        });
    }
    
    /*//医嘱直接打印
    function print()
    {
    	var dataObj = JSON.parse($("#advice_print option:selected").attr("data-info"));
    	var id = dataObj.id;
    	var url = printUrl+"/printtoolrest/jpt/"+id+"?cbm01="+cbm01;
    	document.getElementById('appletDiv').innerHTML="<object classid = 'clsid:CAFEEFAC-0018-0000-0091-ABCDEFFEDCBA'" +
        "WIDTH = '0' HEIGHT = '0' >" +
        "<PARAM NAME = 'code' VALUE = 'com.cnhis.cloudhealth.pmsweb.print.JRPrinterApplet.class'>" +
        "<PARAM NAME = 'codebase'  VALUE = '"+printUrl1+"'>" +
        "<PARAM NAME = 'archive'  VALUE = 'reportprint.jar'>" +
        "<param name = 'type' value = 'application/x-java-applet;version=1.6'>" +
        "<PARAM NAME = 'scriptable' VALUE='false'>" +
        "<PARAM NAME = 'REPORT_URL' VALUE='" + url + "'>" +
        "</object>";
    }*/
 
  //医嘱直接打印
    function print()
    {
    	debugger;
    	if ($(".innerHead td input:checked").length <= 0)
    	{
    		layer.msg("请勾选要打印的医嘱单",
    		{
    		time : 2000,
    		icon : 0,
    		skin: 'layui-layer-msg0'
    		});
    		return;
    	}
    	else if($(".innerHead td input:checked").length > 1)
    	{
    		layer.msg("只能勾选一个已发送的医嘱单",
    				{
    				time : 2000,
    				icon : 0,
    				skin: 'layui-layer-msg0'
    				});
    				return;
    	}
    	else
    	{
    			var dataStr=$($(".innerHead td input:checked").parents("tbody").find(".yizhu_details")[0]).attr("data-info");
    			var dataObj = JSON.parse(dataStr);
    			cbm01 = dataObj.cbm01;
    			var bda01 = dataObj.bda01;
    			var vaf10 = dataObj.vaf10;
    			if(vaf10!=8)
    			{
    				layer.msg("请先发送医嘱单",
    						{
    						time : 2000,
    						icon : 0
    						});
    						return;
    			}
    			var flag = $("#advice_print option:selected").attr("data-info");
    			if(flag){
    				print_content();
    			}else{
    				
    				switch (bda01) {
    					case "1":
    						rid = 24;
    						break;
    					case "8":
    						rid = 25;
    						break;
    					case "E":
    						rid = 22;
    						break;
    					case "L":
    						rid = 23;
    						break;
    					case "S":
    						rid = 28;
    						break;
    					case "T":
    						rid = 190;
    						break;
    				}
    				var myAjax = $.ajax({
    					url : printUrl + "/printtemprest/findListByRid/" + rid+"?jsessionids="+$.cookie('jsessionids'),
    					type : "get",
    					async : true,
    					dataType : "json",
    					traditional : true,
    					success : function(data) {
    						var html;
    						for (var i = 0; i < data.length; i++) {
    							var obj = {};
    							obj.vaf10 = vaf10;
    							obj.id = data[i]['id'];
    							if (data[i]['xdefault'] == "1") {
    								html = '<option data-info='+JSON.stringify(obj)+'>'+data[i]['name']+'</option>';
    							} else {
    								html = '<option data-info='+JSON.stringify(obj)+'>'+data[i]['name']+'</option>';
    							}
    							$("#advice_print").empty().append(html);
    						}
    						print_content();
    					},
    					error : function(XMLHttpRequest, textStatus, errorThrown) {
    						layer.msg('打印服务器连接失败！', {
    							time : 2000,
    							icon : 3,
    							skin: 'layui-layer-msg3'
    						});
    					}
    				});
    			}
    		}
    	
    }
    
 


   
 //系统表格设置 
   //1 表格设置出发事件 
  function tableSetClick(){
	  $("#jy_jingdian_search").on("click",function(){
		  var tablehtml=$("#tableHtml").html();
		  layer.open({
			  type: 1,
			  title: 'tableset',
			  skin: 'layui-layer-rim', //加上边框
			  area: ['50%', '50%'], //宽高
			  content: tablehtml
			});
	  })
  }  
  //2 展示设置界面
  //2.1 展示html
  function showSetTable(){
	  var data =  [ {"name" : "仪器","value" : "bey03a","width":"200"}, {"name" : "样本序号","value" : "lab23","width":"100"}, 
	                {"name" : "病历号","value" : "vaa01","width":"100"}, {"name" : "姓名","value" : "vaa05","width":"100"}, 
	                {"name" : "性别","value" : "acf01","width":"50"}, {"name" : "年龄","value" : "lab12","width":"50"},
		             {"name" : "审核人","value" : "bce03b","width":"100"}, {"name" : "打印","value" : "lab36","width":"50"},
		             {"name" : "检验时间","value" : "lab20","width":"100"},{"name" : "样本ID","value" : "lab22","width":"50"}, 
		             {"name" : "类别","value" : "abw02","width":"50"}, {"name" : "核收时间","value" : "bck01a"	,"width":"100"},
		             {"name" : "样本类型","value" : "abb02","width":"100"} , {"name" : "创建时间","value" : "lab60","width":"100"},
		             {"name" : "病人科室","value" : "bce03d","width":"800"}, {"name" : "出生日期","value" : "lab14","width":"100"},
		             {"name" : "病人类别","value" : "bdp02","width":"500"}, {"name" : "床号","value" : "lab16","width":"50"},
		             {"name" : "生理特征","value" : "bes02","width":"100"}, {"name" : "诊断","value" : "lab18","width":"100"}, 
		             {"name" : "标本形态","value" : "bew02","width":"100"}, {"name" : "执行科室","value" : "bck03c","width":"100"}, 
		             {"name" : "样本条码","value" : "lab42","width":"100"}, {"name" : "采样人","value" : "bce03a","width":"100"}
		             , {"name" : "核收人","value" : "bce03c","width":"100"}, {"name" : "检验人","value" : "bce03d","width":"100"}, 
		             {"name" : "审核时间","value" : "lab53","width":"100"} , {"name" : "申请科室","value" : "bck03b","width":"100"}, 
		             {"name" : "病区","value" : "bck01d","width":"100"}, {"name" : "工作单位","value" : "baq03","width":"100"}]
	  var html;
	  for (var i = 0; i < data.length; i++) {
		  html += "<tr class="+data[i].value+">";
		  html += "<td>"+(i+1)+"</td>";
		  html += "<td><input type='checkbox' /></td>";
		  html += "<td>"+data[i].name+"</td>";
		  html += "<td>"+data[i].name+"</td>";
		  html += "<td><input type='text' value='"+data[i].width+"'/></td>";
		  html += "</tr>";
		}
	  $("#set_table_tbody").append(html);
	  saveSetEvent()
  }
   
  
  //3 设置参数
  //1 点击确定按钮，执行该操作
  function saveSetEvent(){
//	  $("#saveSetBtn").on("click",function(){
		  var setArr=[];
		  var styleArr=[];
		  $("#set_table_tbody").find("input[type='checkbox']").each(function(i,e){
			  if($(e).prop("checked")){
				  var classname=$(e).parents("tr").attr("class");
				  var elewidth=$(e).parents("tr").find("input[type='text']").val();
				  $('.'+classname).css({width:elewidth});
				  styleArr.push(elewidth);
				  setArr.push(classname);
			  }
		  })
		  $("#jingdian_left_table table").find("td").hide();
		  $("#jingdian_left_table table").find("th").hide();
		  for(var i=0;i<setArr.length;i++){
			  $("#jingdian_left_table table").find("."+setArr[i]).show();
		  }
//	  })
		  var minwidth=0;
		  for (var j=0;j<styleArr.length;j++){
			  minwidth +=parseInt(styleArr[j]);
		  }
		  $("#jingdian_left_table table").css({'min-width':minwidth});
	  
  }
  
  
  
////点击DIV之外的区域，div消失
	document.onclick = function (event) {     
		 var e = event || window.event;  
		 var elem = e.srcElement||e.target; 
		 while(elem) {   
		        if(elem.className == "bootstrap-tagsinput"||elem.className=="selectDiv"||elem.className=="list-group-item node-bangliruyuan-tree"||
		        	elem.className=="list-group-item node-tree"||elem.id=="tree-table"||elem.className=="laypage_main laypageskin_default"||
		        	elem.className=="selectDiv"||elem.className=="div_show"||elem.className=="list-group-item node-bangliruyuan-tree node-selected")
		        {  
		                return ;  
		        }  
		        elem = elem.parentNode;       
		    }
			 $(".selectDiv").hide();
			 
	}
